<template>
  <div class="powerexam index">
    <Header></Header>
    <div class="main2">
      <p class='current-nav'>当前位置 : <router-link to='index'>首页</router-link> <i> > </i>
        <router-link to='assessed'>{{varname}}应急预案评估</router-link> <i> > </i>附件要素评估
      </p>

      <div class="infor search">
        <div class="form-container clearfix">
          <div class="left-box">
<p v-if="tit.length > 0" style="color:#4080ff;line-height:680px;text-align:center;font-size:14px;">{{tit}}</p> 
            <iframe v-else :src="leftImg"
                    frameborder="0"
                    scrolling="no"
                    width="100%"
                    height="100%"></iframe>
           
          </div>
          <div class="right-box">
            <div class='bts-group'>
              <el-button v-for='(item,index) in uploadType'
                         :key='index'
                         @click='goPath(item.path)'
                         :class='activeIndex==index ? "sure":""'>{{item.name}}</el-button>
            </div>
            <h3 class="table-name">电力企业应急预案附件要素评估表</h3>
            <table border="1"  v-if='data.length>0'>
              <thead>
                <tr>
                  <th rowspan="2">评估项目</th>
                  <th rowspan="2">评估内容及要求</th>
                  <th colspan="3"> 评估意见</th>
                </tr>
                <tr>
                  <th>符合</th>
                  <th>不符合</th>
                  <th>基本符合</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td>{{data[0].reviewItemTwo}}</td>
                  <td>
                    <p> {{data[0].reviewContent}}</p>
                  </td>
                  <td v-for='item in radios'
                      :key='item'
                      @click='raiosIndex1=item'
                      :class="raiosIndex1 == item ? 'div-radio1' : 'div-radio2'"></td>
                </tr>
                <tr>
                  <td>{{data[1].reviewItemTwo}}</td>
                  <td>
                     <p> {{data[1].reviewContent}}</p>
                  </td>
                  <td v-for='item in radios'
                      :key='item'
                      @click='raiosIndex2=item'
                      :class="raiosIndex2 == item ? 'div-radio1' : 'div-radio2'"></td>
                </tr>
                <tr>
                  <td>{{data[2].reviewItemTwo}}</td>
                  <td>
                     <p> {{data[2].reviewContent}}</p>
                  </td>
                  <td v-for='item in radios'
                      :key='item'
                      @click='raiosIndex3=item'
                      :class="raiosIndex3 == item ? 'div-radio1' : 'div-radio2'"></td>
                </tr>

                <tr>
                  <td style="width:120px;">{{data[3].reviewItemTwo}}</td>
                  <td style="width:300px;">
                    <p> {{data[3].reviewContent}}</p>
                  </td>
                  <td v-for='item in radios'
                      :key='item'
                      @click='raiosIndex4=item'
                      :class="raiosIndex4 == item ? 'div-radio1' : 'div-radio2'"></td>
                </tr>
                <tr>
                  <td style="width:120px;">{{data[4].reviewItemTwo}}</td>
                  <td style="width:300px;">
                    <p> {{data[4].reviewContent}}</p>
                  </td>
                  <td v-for='item in radios'
                      :key='item'
                      @click='raiosIndex5=item'
                      :class="raiosIndex5 == item ? 'div-radio1' : 'div-radio2'"></td>
                </tr>
                <tr>
                  <td colspan="5"
                      style="text-align:left;">
                    <p>注 : 附件根据应急工作需要动态设置,部分项目可省略。</p>
                  </td>
                   </tr>
                <tr>
                  <td>评估专家签字</td>
                  <td colspan="4"  class="sign-word">
                    <img  :src="signImg" alt="">    
                  </td>
                </tr>
              </tbody>
            </table>
            <div class="bts">

              <el-button class='sure' @click="saveData(0)">保存</el-button>
              <el-button class='sure'
                         @click='saveData(1)'>下一步</el-button>
            </div>
          </div>

        </div>
      </div>
    </div>
    <Footer />
  </div>
</template>
<script>
import Header from '../common/header2'
import Footer from '../common/footer'
import config from '../../config.js'
export default {
  components: {
    Header,
    Footer
  },
  data () {
    return {
      data:[],
      leftImg:'',
      tit:"",
      signImg:'',
      autograph:'',
      raiosIndex1: 4,
      varname:'',
      raiosIndex2: 4,
      raiosIndex3: 4,
      raiosIndex4: 5,
       raiosIndex5: 4,
      radios: [1, 2, 3],
      uploadType: [
        {
          name: '形式评估',
          path: 'situationexam'
        },
        {
          name: '要素评估',
          path: 'keyexam'
        },
        {
          name: '附件要素评估',
          path: 'powerexam'
        },
        {
          name: '个人评估意见',
          path: 'personexam'
        }
      ],

      activeIndex: 2,
    };
  },
  mounted(){
     this.getData()
    this.getLeftUrl()
      this.signImg = localStorage.signImg
      this.autograph= localStorage.autograph
  },
  methods:{
    goPath(path){
      this.saveData(2,path)
    },
      getData(){
       this.postData(0, 3)
        .then( res=> {
            if (res.data.meta.success) {
                this.varname = res.data.data.companyName
                res.data.data.list.map((item,index)=>{
                  if(item.selectResult){

                   this['raiosIndex'+(index+1)] = item.selectResult
                  }
                })
                this.data = res.data.data.list
            } else {
               this.$message.warning(res.data.meta.message)
            }
        })
        .catch(function (res) {
           console.log(res)
        })
    },
   lookstatus(item){
          let  baseUrl = item.viewUrl;
          var urlpath = baseUrl.indexOf("?") + 1;
          urlpath = baseUrl.substring(urlpath);
          var arrapi = urlpath.split("&");
          let  uesrMessage = {}
          arrapi.forEach(
              (item)=>{
                  var brrapi = [];
                  brrapi = item.split("=");
                  uesrMessage[brrapi[0]] = brrapi[1];
              }
          )

          let id = uesrMessage.srcFid;
          let  expires = Date.parse(new Date());
          let a = "FastDFS1234Bossien"+id +expires
          console.log(a);
          let token = this.$md5(a)
          token = token.toUpperCase()
          let that = this;
          $.ajax({
              url:config.baseUrl3+"queryPublishFileInfo.do?appId=001&srcFid="+id+"&expires="+expires+"&token="+token,
              type:'GET', //GET
              async:false,    //或false,是否异步
              data:{
              },
              timeout:5000,    //超时时间
              success:function(data,textStatus,jqXHR){
                let status = JSON.parse(data);
                if(!status.success){
                   that.tit = '文件正在转码中...'
                }
                if(status.dataObj.srcFileStatusName=="12"){
                    that.leftImg = item.viewUrl
                }else{
                    that.tit = '文件正在转码中...'
                }
              },
              error:function(xhr,textStatus){
              },
              complete:function(){
              }
          })
      },
     getLeftUrl(){
      this.postData(1)
          .then(res => {
            if (res.data.meta.success) {
             this.lookstatus(res.data.data)
            } else {
              this.$message.warning(res.data.meta.message)
            }
          })
          .catch(response => {
            console.log(response);
          });
    },
    saveData(n,path){
      let list=[]
      let flag=false
      this.data.map((item,index)=>{
        if(item.intOrder!=6){
if(this['raiosIndex'+(index+1)] == 4){
           flag=true
        }else{
          let obj={
                tableId:item.id,
            result:this['raiosIndex'+(index+1)] 
          }
          list.push(obj)
        }
        }
        
       
      })
     
      
      if(flag){
         this.$message.warning('请选择完毕后再保存')
      }else{
       
      this.postData(2,3,list,this.autograph)
          .then(res => {
            if (res.data.meta.success) {
              if(n==1){
                 this.$router.push('personexam')
              }else if(n==2){
               this.$router.push(path)
              }else{
                
              this.$message.success(res.data.meta.message)
              }
            } else {
              this.$message.warning(res.data.meta.message)
            }
          })
          .catch(response => {
            console.log(response);
          });
          

      }

    }
  }
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang='less'>
@import "../../../static/css/information.less";
.powerexam {
  .search {
    .form-container {
      padding: 0 0 70px;
      margin: 0 auto;
      .bts-group {
        width: 510px;
        margin: 0 auto 30px;
        .el-button {
          width: 120px;
          color: #3f80fe;
          border-radius: 8px;
          border: 1px solid #3f80fe;
        }
        .sure {
          color: #fff;
          background: #4080ff;
          background: linear-gradient(90deg, #6eb1ff 20%, #3372ff 80%);
        }
      }
      .bts {
        text-align: center;
        width: 100%;
        .el-button {
          float: none;
        }
        .sure {
          color: #fff;
          background: #4080ff;
          background: linear-gradient(90deg, #6eb1ff 20%, #3372ff 80%);
        }
      }
      tr {
        td:nth-child(2) {
          p {
            line-height: 30px;
            text-align: left;
          }
        }
      }
    }
  }
}
</style>